home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9212.ZIP / embed.asc < prev    next >
Text File  |  1992-11-30  |  2KB  |  92 lines

  1. _SIMULATION AND TESTBOARD FOR EMBEDDED SYSTEM DESIGN_
  2. by Michael Kutter
  3.  
  4.  
  5. [LISTING ONE]
  6.  
  7. FILE *serial_in,*serial_out;
  8.  
  9. void outbyte(unsigned char dest,value)
  10.      {
  11.      static long command;
  12.      /* check to make sure dest indicates SERIAL_DEVICE. */
  13.      if (dest != SERIAL_DEVICE)
  14.           {
  15.           printf("Error in Hardware destination address\n");
  16.           return;
  17.           }
  18.      /* reconstruct the command by shifting bits into the */
  19.      /* command variable. */
  20.      if (control bit in value indicates a new command bit
  21.                has been sent)
  22.           {
  23.           command += new input bit in "value";
  24.           command <= 1;
  25.           }
  26.      /* record the command after it is complete */
  27.      if (latch bit in value indicates the command is complete)
  28.           {
  29.           fprintf(serial_out,"serial command: %lx",command);
  30.  
  31.           command = 0;
  32.           }
  33.      }
  34. unsigned char inbyte(unsigned char source)
  35.      {
  36.      static long status;
  37.      unsigned char return_byte = 0;
  38.  
  39.      /* check to make sure dest indicates SERIAL_DEVICE. */
  40.      if (source != SERIAL_DEVICE)
  41.           {
  42.           printf("Error in Hardware destination address\n");
  43.           return;
  44.           }
  45.      /* get a new status word */
  46.      if (latch bit in value indicates a new status read)
  47.  
  48.           fscanf(serial_in,"%lx",&status);
  49.      /* send the status one bit at time, shifting bits  */
  50.      /* out of the status variable */
  51.      if (control bit in status indicates a new statu bit
  52.                has been requested)
  53.           {
  54.           return_byte = status & 0x01;
  55.           status >= 1;
  56.           }
  57.      return(return_byte);
  58.      }
  59.  
  60.  
  61.  
  62. Example 1: Basic RPSC macros
  63.  
  64. #define inbyte(b)     (*((unsigned char *)b))
  65. #define outbyte(a,b)  (*((unsigned char *)a)=(unsigned char)b)
  66.  
  67.  
  68.  
  69.  
  70. Example 2: You can replace macros with subroutines like these that read from and write to text files
  71.  
  72. FILE *sim_out;      /* opened at beginning of simulation */
  73.                     /* closed at end. */
  74. FILE *sim_in[ONE_FOR_EACH_REGISTER];
  75.  
  76. unsigned char inbyte(unsigned char address)
  77.      {
  78.      int invalue;
  79.  
  80.      fscanf(sim_in[address],"%x",&invalue);
  81.      return(0xFF & invalue);
  82.      }
  83.  
  84. void outbyte(unsigned char dest,value);
  85.      {
  86.      fprintf(sim_out,"%x <-- %x\n",dest,value);
  87.  
  88.      }
  89.  
  90.  
  91.  
  92.